#!/usr/bin/php
<?php

/* 
 This is the domain name stub creator. This script should be run when a new domain is added to the 
 FQDN table. This script will then go in and take the fqdn, and create the basic hosts for the domain 
 in the records table. The basic hosts are : 
 
 NS, 
 MX,
 @,
 www
 mail
 smtp
 mailadmin
 webmail
 ftp
 stats
 
 
*/

require_once '/etc/binder.conf'; 
require_once(INCLUDE_PATH."/Records.class.php"); 


$sql = "select * from fqdn where new='Y'"; 
$rs = $db->mRun($sql) ; 

$nr = $db->_NumRows ; 

if($nr > 0) {
echo "$nr new Domains were found \n"; 

while($row=mysql_fetch_assoc($rs)) {
	$r = new DNSRecord(); 
	
	$fqdn = $row['fqdn']; 
	$ttl = $row['ttl']; 
	$serial = $row['serial']; 
	$refresh = $row['refresh']; 
	$retry = $row['retry']; 
	$expiry = $row['expiry']; 
	$minimum = $row['minimum']; 
	$soa = $row['soa']; 
	$new = $row['new'] ; 
	$defaultip = $row['defaultip']; 
	$fqdnid = $row['fqdnid']; 
	$r->_strId = $row['fqdnid']; 
	echo "Adding $intNumDefaultHosts Hosts for $fqdn \n"; 
	
	#for($i=0; $i<$intNumDefaultHosts;$i++) {
	foreach($arrDefaultHosts as $key => $value) {
		echo "\tAdding $key.$fqdn with the ip of $value \n"; 
		$r->mSetIp($value);
		$r->mSetHostName($key);
		if($key == "mail") {
			$r->mSetType($type="MX");
			$r->mSetPriority($priority="10");
		} else {
			$r->mSetType($type="A");
			$r->mSetPriority($priority="0");
		}
		
		$r->mInsert(); 
	}
	
	#Now go and set the new value to N. 
	
	$sql = "update fqdn set new='N',serial='$serial' where fqdnid='$fqdnid'"; 
	$db->mInsert($sql) ; 
	unset($r); 
	
}
} else { 
	echo "No New Domains were found. Nothing to do.\n"; 
} 



?>
